var userInfoUrl = "http://mumobile30.ceair.com/mas/sdk10098/public/myTask/QueryB2eUserInfo?item=";
var userId = localStorage['MU30-lOGIN-USRNAME'];
var userPwd = localStorage['MU30-lOGIN-PASSWORD'];

var DATE=''; //格式xxxx-xx-xx

var UrlClient = "http://mpservice.ceair.com/WebServiceClient?RequestKey=FDDBCAA11500948183F0299431B2B571";//正式地址
//var UrlClient = "http://mgstest.ceair.com:8080/WebServiceClient?RequestKey=FDDBCAA11500948183F0299431B2B571";//测试地址
/**
@business_list
业务资料列表
*/
var business_list_url = "http://172.28.28.21:5566/DfHbWebService/HbWebService.asmx?wsdl";
var business_list_nameSpace = "http://tempuri.org/";
var business_list_function = "GetBusinessMaterial";
/**
@business_content
业务资料详细
*/
var business_content_url = "http://172.28.28.21:5566/DfHbWebService/HbWebService.asmx?wsdl";
var business_content_nameSpace = "http://tempuri.org/";
var business_content_function = "GetBusinessMaterialContent";
/**
@scheduling
排班查询日历
*/
var scheduling_url = "http://172.17.61.136/SQLDataAccessWebService/SQLDataAccessWebService.asmx";
var scheduling_nameSpace = "http://sqlws.hcc.ceair.com/";
var scheduling_function = "MobileServiceGetOndutyEmployeeNumber";
/**
@scheduling_list
排版查询列表
*/
var scheduling_list_url = "http://172.17.61.136/SQLDataAccessWebService/SQLDataAccessWebService.asmx";
var scheduling_list_nameSpace = "http://sqlws.hcc.ceair.com/";
var scheduling_list_function = "MobileServiceGetEmployeeFactActivityByPaging";

/**
 * 获取个人绩效
 */
var KPIUrl="http://flymt.ceair.com/achievements/ClickRate?";
function getKPIdata(callback)
{
    var userId = localStorage['MU30-lOGIN-USRNAME'];
    // var userId ="yinzhihua";
    var time = GetDateStr(-4);
    Loading(0);
    $.ajax({ 
             type: "GET",
             url: KPIUrl+"no="+userId+"&time="+time,
             // url: KPIUrl,
             data:'',
             dataType: "json",
             success: function(json){
                  // console.log(JSON.stringify(json));
                  Loading(-1);
                  callback(json);
             },
             error: function(erro){
                alert(JSON.stringify(erro));
             }
         });
}

/**
 * 获取时间：年-月-日
 */
function getTime()
{
    var d = new Date();
    var vYear = d.getFullYear();
    var m=d.getMonth() + 1;
    var vMon =m>=10?m: "0"+m;
    var day=d.getDate();
    var vDay =day>=10?day: "0"+day;
    
    DATE=vYear+"-"+vMon+"-"+vDay;
}
function getToDoList()
{
   // userId = "yinzhihua";
    var item = '{"userUid":"' + userId + '"}';
         item = encodeURIComponent(item);
    userInfoUrl = userInfoUrl + item;
    $.ajax({ 
             type: "GET",
             url: userInfoUrl,
             contentType: 'text/html;charset=utf-8',
             data:"",
             dataType: "json",
             success: function(json){
                  // console.log(JSON.stringify(json));
                  var userType=json.data.OrgNamePath;
                  var queryUrl='';
                  if(userType.indexOf("东航集团") > -1)
                  {
                      queryUrl="http://mumobile30.ceair.com/mas/sdk10098/public/myTask/QueryToDoTaskForMobile";
                  }else{
                      queryUrl="http://mumobile30.ceair.com/mas/sdk10098/public/myTask/QueryToDoTasks";
                  }
                  queryToDoTask(queryUrl);
             },
             error: function(erro){
                alert(JSON.stringify(erro));
             }
         });
}
var list;
function  queryToDoTask(queryUrl){
    console.log(queryUrl);
    userPwd="Passwor2=";
    // alert(userId+"/"+userPwd)
    data1={userUid : encodeURIComponent(userId),
          pwd : encodeURIComponent(userPwd),
          pageIndex : 0,
          pageSize : 10
         };
    $.ajax({ 
             type: "POST",
             url: queryUrl,
             data:data1,
0             dataType: "json",
             success: function(json){
                   // console.log(JSON.stringify(json));
                 if(json.status==0)
                 {
                     var taskArr=json.message.QueryToDoTasksResult.Items.MuMobileTaskEntity;
                     list=taskArr;
                     var len=taskArr.length;
                     var str='';
                     for(var i=0;i<len;i++)
                     {
                         var time=taskArr[i].BeginTime;
                         var tArr=time.split("T");
                         var dateStr=tArr[0];
                         var timeStr=tArr[1].substr(0,8);
                         var timetxt='';
                         if(dateStr==DATE)
                         {
                             timetxt=timeStr;
                         }else{
                             var dArr=dateStr.split("-");
                             timetxt=dArr[0].substr(2,2)+"/"+dArr[1]+"/"+dArr[2];
                             
                         }
                         str+='<div class="ub bd_b lh13 mt3 mb4 fs9 ml8 todoPageIndex" todoList id="' + i + '">\
                            <div class="ub-f3 w100">\
                                <div class="c0 zformat">'+taskArr[i].Title+'</div>\
                                <div class="c25">'+taskArr[i].TaskSource+'</div>\
                            </div>\
                            <div class="ub ub-f1 c25 pt3 w20 tx-r">'+timetxt+'</div>\
                        </div>';
                        
                     }
                     str+='<div class="lh13 mt3 mb4 fs8 mr18 tx-r c0097F3" ><span onclick="moreToDo()">查看更多...</span></div>';
                     $("#toDoList").html(str);
                     var count=json.message.QueryToDoTasksResult.TotalCount;
                     $("#toDOCount").html("("+count+")");
                     todoItemclickHandler()
                 }  
             },
             error: function(erro){
                alert(JSON.stringify(erro));
             }
         });
}
/**
 * 设置当前页面json数据
 */
function currentJosn(wsdl,nameSpace,paras,values,method,SOAPType)
{
   
  var jsonPage =[{'key':'wsdl','type':'0','value':wsdl},{'key':'KEY1','type':'0','value':'1'},
 {'key':'KEY2','type':'0','value':'1'}, {'key':'KEY3','type':'0','value':'1'}, {'key':'nameSpace','type':'0','value':nameSpace}, {'key':'method','type':'0','value':method}, {'key':'paras','type':'0','value':paras}, {'key':'values','type':'0','value':values}];
    var SOAPTypeA = "yes";
    if(SOAPType!=""&&SOAPType!=undefined)
    {
        SOAPTypeA = "no";
    }
    A.getJSON(UrlClient+"&SOAPType="+SOAPTypeA,function(json){
                        var currentJosnStr = JSON.stringify(json);
                        returnjson(currentJosnStr);         
            },"json",function(e){alert(JSON.stringify(e))},"POST",jsonPage,false);
}

/**
 * 设置json数据
 */
function setLocalJosn(wsdl,nameSpace,paras,values,method,SOAPType,winName,winUrl)
{

    var jsonPage =[{'key':'wsdl','type':'0','value':wsdl},{'key':'KEY1','type':'0','value':'1'},
 {'key':'KEY2','type':'0','value':'1'}, {'key':'KEY3','type':'0','value':'1'}, {'key':'nameSpace','type':'0','value':nameSpace}, {'key':'method','type':'0','value':method}, {'key':'paras','type':'0','value':paras}, {'key':'values','type':'0','value':values}];
    var SOAPTypeA = "yes";
    if(SOAPType!=""&&SOAPType!=undefined)
    {
        SOAPTypeA = "no";
    }
    // console.log(jsonPage)
    A.getJSON(UrlClient+"&SOAPType="+SOAPTypeA,function(json){
                        // var jsonStr = JSON.stringify(json);
                       calendarjson(json);
                            
            },"json",function(e){},"POST",jsonPage,false);
}
/**
 * 设置带有内容转换的json数据
 */
function contentJosn(wsdl,nameSpace,paras,values,method,winName,winUrl,SOAPType)
{
  var jsonPage =[{'key':'wsdl','type':'0','value':wsdl},{'key':'KEY1','type':'0','value':'1'},
 {'key':'KEY2','type':'0','value':'1'}, {'key':'KEY3','type':'0','value':'1'}, {'key':'nameSpace','type':'0','value':nameSpace}, {'key':'method','type':'0','value':method}, {'key':'paras','type':'0','value':paras}, {'key':'values','type':'0','value':values}];
    var SOAPTypeA = "yes";
    if(SOAPType!=""&&SOAPType!=undefined)
    {
        SOAPTypeA = "no";
    }
    
    A.getJSON(UrlClient+"&act=norep&SOAPType="+SOAPTypeA,function(json){
                        var jsonStr = JSON.stringify(json);
                        localStorage.setItem("zvData",jsonStr);
                        //openNewWin(winName, winUrl);
                        uexWindow.open(winName, 0, winUrl, 2, "", "", 0);
            },"json",function(e){},"POST",jsonPage,false);
}
/**@Function strToJson
  @param {Object} str
   字符串转换json方法
 */
function strToJson(str){ 
    var json = eval('(' + str + ')'); 
    return json; 
}
/**
 *获取某年某月有多少天 
 */
function getDaysInMonth(year,month){
    var curDate = new Date();
    curDate.setMonth(month);
    curDate.setDate(0);
    return curDate.getDate();
}
function moreToDo()
{
    openCiTie('我的待办','sdk10018');
}
function moreNotice()
{
    openCiTie('业务资料','11363970');
}
/**
 * [openCiTie 跳转相应磁贴]
 * @param  {[type]} name [磁贴名字]
 * @param  {[type]} id   [项目id]
 * @return {[type]}      [description]
 */
function openCiTie(name,id){
    uexWindow.evaluateScript('today', '0', 'openTab("'+name+'","'+id+'");');
}
/*
 * 点击待办列表条目
 */
function todoItemclickHandler()
{
    $("[todoList]").click(function() {
        var index = this.id;
        var aa = list[index].IsSupport;
        var bb = list[index].SupportType;
        var taskKindCode = list[index].TaskKindCode;
        var taskSource = list[index].TaskSource;
        if (!aa) {
            uexWindow.toast('0', '5', '请到pc端处理该待办', '1500');
        } else {
            //返回时需要刷新
            isNeedRefresh = true;
            if (taskKindCode == "DocumentNew" && (taskSource == "信息部运维类付款" || taskSource == "信息部投资类付款")) {
                //若为"发票审批"，则在掌上东航打开"合同审批"磁贴
                localStorage.setItem('goList', '2');
                uexWindow.publishChannelNotification('1006', 'openTabByName("sdk10250","合同审批","task,tool_me")');
            } else if (bb == 2 && taskKindCode == "CWZJ") {
                //若为"财务资金系统"类别，则在掌上东航打开"资金管理"磁贴
                uexWindow.publishChannelNotification('1006', 'openTabByName("sdk10108","资金管理","task,tool_me")');
            } else if (bb == 2 && taskKindCode == "TCS_HT") {
                //若为"合同审批"类别，则在掌上东航打开"合同审批"磁贴
                localStorage('goList', '1');
                uexWindow.publishChannelNotification('1006', 'openTabByName("sdk10250","合同审批","task,tool_me")');
            } else if (bb == 2 && taskKindCode == "ZSDH_YJFK") {
                //若为"it意见反馈"类别，则在掌上东航打开"IT系统意见反馈"应用
                uexWindow.publishChannelNotification('11262631', '');
            } else {
                localStorage.setItem('daiban_detail_url', list[index].ActionUrl + '&fromZsdh=1');
                uexWindow.open('daiban', 0, 'daibanDetail.html', 10, '', '', 0);
            }
        }
    });
}

function openUrl(Id)
{
    // Loading(0);
    var wsdl =  business_content_url 
    var nameSpace =  business_content_nameSpace 
    var paras = "id";
    var values =Id; 
    var method = business_content_function 
    contentJosn(wsdl,nameSpace,paras,values,method,"business_information_detail","business_information_detail.html");
}
/************************  common  ***********************?
/**打开日期控件*/
function openDate(year,month,day,callback){
    uexControl.openDatePicker(year,month,day);
    uexControl.cbOpenDatePicker=function(opCode,dataType,data){
        if(dataType==1){
            data = JSON.parse(data);
            if(data.month<10) data.month = "0" + data.month;
            if(data.day<10) data.day = "0" + data.day;
            var json = {
                year : data.year,
                month : data.month,
                day : data.day,
            };
            callback(json);
        }
    }   
};

//获取年
getYear = function(date){
    if(date == undefined) date = new Date;
    return date.getFullYear();
};
//获取月
getMonth = function(date){
    if(date == undefined) date = new Date;
    var month = date.getMonth() + 1;
    if(month < 10) month = "0" + month;
    return month;
};
//获取日
getDay = function(date){
   if(date == undefined) date = new Date;
    var day = date.getDate();
    if(day < 10) day = "0" + day;
    return day;
};
//获取当前日期
getDateToday = function(date){
    return getYear() + "-" + getMonth() + "-" + getDay();
};
//获取星期
getWeek = function(date){
    if(date == undefined) date = new Date;
    var week = date.getDay();
    var weekArr = ["日","一","二","三","四","五","六"];
    return weekArr[week];
};
//获取小时
getHours = function(date){
    if(date == undefined) date = new Date;
    return date.getHours();
},
//获取分钟
getMinutes = function(date){
    if(date == undefined) date = new Date;
    return date.getMinutes();
};


function ChangeDateToString(DateIn) {
    var Year = 0;
    var Month = 0;
    var Day = 0;
    var CurrentDate = "";
    //初始化时间
    Year = DateIn.getFullYear();
    Month = DateIn.getMonth() + 1;
    Day = DateIn.getDate();

    CurrentDate = Year + "-";
    if (Month >= 10) {
        CurrentDate = CurrentDate + Month + "-";
    } else {
        CurrentDate = CurrentDate + "0" + Month + "-";
    }
    if (Day >= 10) {
        CurrentDate = CurrentDate + Day;
    } else {
        CurrentDate = CurrentDate + "0" + Day;
    }

    return CurrentDate;
}

function compareTime(startDate, endDate) {
    if (startDate.length > 0 && endDate.length > 0) {
        var arrStartDate = startDate.split("-");
        var arrEndDate = endDate.split("-");

        var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], '00', '00', '00');
        var allEndDate = new Date(arrEndDate[0], arrEndDate[1], arrEndDate[2], '00', '00', '00');

        if (allStartDate.getTime() <= (allEndDate.getTime())) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

/**
 * 时间选择
 */
function checked_day(id){
        //var date = getNowFormatDate();
        var date=$$(id).innerHTML
        var dateArr = date.split("-");
        uexControl.openDatePicker(dateArr[0],dateArr[1],dateArr[2]);
             uexControl.cbOpenDatePicker = function(opId, dataType, data){
                if (dataType == 1) {
                    var obj = eval('(' + data + ')');
                    var CurrentDate = "";
                    
                   var Year    = obj.year;
                   var Month = obj.month; 
                   var Day = obj.day;
                   CurrentDate += Year + "-"; 
                   if (Month >= 10 ) 
                   { 
                    CurrentDate += Month + "-"; 
                   } 
                   else
                   { 
                    CurrentDate += "0" + Month + "-"; 
                   } 
                   if (Day >= 10 ) 
                   { 
                    CurrentDate += Day ; 
                   } 
                   else
                   { 
                    CurrentDate += "0" + Day ; 
                   } 
                    
                    $$(id).innerHTML = CurrentDate;
                }
            }
 }
 function getNowFormatDate() 
{ 
           var day = new Date(); 
           var Year = 0; 
           var Month = 0; 
           var Day = 0; 
           var CurrentDate = ""; 
           //初始化时间 
           //Year       = day.getYear();//有火狐下2008年显示108的bug 
           Year       =  day.getFullYear();//ie火狐下都可以 
           Month      = day.getMonth()+1; 
           Day        = day.getDate(); 
           CurrentDate += Year + "-"; 
           if (Month >= 10 ) 
           { 
            CurrentDate += Month + "-"; 
           } 
           else
           { 
            CurrentDate += "0" + Month + "-"; 
           } 
           if (Day >= 10 ) 
           { 
            CurrentDate += Day ; 
           } 
           else
           { 
            CurrentDate += "0" + Day ; 
           } 
           return CurrentDate; 
} 
function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth()+1;//获取当前月份的日期
    var d = dd.getDate();
    m=m>=10?m: "0"+m;
    d=d>=10?d: "0"+d;
    return y+"-"+m+"-"+d;
}